<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Testing websockets</title>
</head>
<body>
  <div>
    <input type="submit" value="Start" onclick="start()" />
    <input type="submit" value="Close" onclick="stop()" />
  </div>
  <div id="messages"></div>
  <script type="text/javascript">
    var webSocket = 
      new WebSocket('ws://localhost:8180/prf-game/websocket-one');

    webSocket.onerror = function(event) {
      onError('ws onError: '+event)
    };

    webSocket.onopen = function(event) {
      onOpen(event)
    };

    webSocket.onmessage = function(event) {
      onMessage(event)
    };

    function onMessage(event) {
      document.getElementById('messages').innerHTML 
        += '<br />' + event.data;
    }

    function onOpen(event) {
      document.getElementById('messages').innerHTML 
        = 'Connection established';
    }

    function onError(event) {
      alert('onError: '+event.data);
    }

    function start() {
        webSocket.send('hello');
        return false;
    }
    function stop() {
        webSocket.close();
        document.getElementById('messages').innerHTML 
        += '<br />' + 'Connection closed';
        return false;
    }
  </script>
</body>
</html>